#include "options_dialog.h"
#include "options_manager.h"

const char* SUPPORTED_COLORS[] = {"2", "16", "256"};

OptionsDialog::OptionsDialog ()
  : DialogBase ("Options Dialog", true, false), colorsLbl_("Colors")
{
  mgr_ = OptionsManager::getInstance ();
  for (int i=0; i<(int) (sizeof(SUPPORTED_COLORS)/sizeof(SUPPORTED_COLORS[0])); i++)
    colorsCbo_.append_text (SUPPORTED_COLORS[i]);
  colorsCbo_.set_active_text ("256");
  overwriteChk_.set_label ("Prompt to overwrite icon file");
  hBox_.add (colorsLbl_);
  hBox_.add (colorsCbo_);
  colorsCbo_.set_tooltip_text ("FIXME");
  overwriteChk_.set_tooltip_text ("If output file already exists, prompt user to overwrite");
  this->get_vbox ()->add (hBox_);
  this->get_vbox ()->add (overwriteChk_);
  this->add_button (Gtk::Stock::OK, Gtk::RESPONSE_OK);
  this->set_default_response (Gtk::RESPONSE_OK);
  this->get_action_area ()->set_layout (Gtk::BUTTONBOX_CENTER);

  char buf[8];
  memset (buf, '\0', sizeof(buf));
  sprintf (buf, "%d", mgr_->getColors ());
  colorsCbo_.set_active_text (buf);

  bool overwrite = mgr_->getOverwriteFileFlag ();
  overwriteChk_.set_active (overwrite);

  this->show_all_children ();
}

OptionsDialog::~OptionsDialog ()
{

}

void OptionsDialog::doSave ()
{
  int colors = atoi (colorsCbo_.get_active_text ().c_str ());
  mgr_->setColors (colors);
  mgr_->setOverwriteFileFlag (overwriteChk_.get_active ());
}
